package com.youme.api

import com.hyphenate.easeim.BuildConfig
import com.youme.model.AddressDirect
import com.youme.model.CreatOrder
import com.youme.model.Direct
import com.youme.model.DirectNone
import com.youme.model.FoodList
import com.youme.model.FriendCircleDetail
import com.youme.model.FriendCircleItem
import com.youme.model.ListAddressDirect
import com.youme.model.ListFood
import com.youme.model.ListOrderDirect
import com.youme.model.ListRestDirect
import com.youme.model.ListRoom
import com.youme.model.ProductsDirect
import com.youme.model.ProfileDirect
import com.youme.model.result.Resp
import io.reactivex.Observable
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query

/**
 * @Time:2021/3/16 9:47
 * @Author:wujinsheng
 * @Description:
 */
val BASE_URL = if (BuildConfig.APP_DEVELOP) "http://301f437880.eicp.vip/" else "http://39.101.132.116:8080/"

interface YouMeApi {
    /**
     * 用户接口
     */
    interface User {
        /**
         * 用户发送验证码
         * type 1为登录 2为注册 3为忘记密码
         */
        @FormUrlEncoded
        @POST("/rest/user/code")
        fun code(
            @Field("phone") phone: String,
            @Field("type") type: Int
        ): Observable<DirectNone>

        @FormUrlEncoded
        @POST("/rest/user/reg")
        fun reg(
            @Field("code") code: String,
            @Field("password") password: String,
            @Field("phonenumber") phonenumber: String,
            @Field("userName") userName: String
        ): Observable<DirectNone>

        @FormUrlEncoded
        @POST("/rest/user/formLogin")
        fun formLogin(
            @Field("username") username: String,
            @Field("password") password: String
        ): Observable<Direct<String>>

        @POST("/rest/user/mobileLogin")
        fun mobileLogin(@Body body: RequestBody): Observable<Direct<String>>

        @FormUrlEncoded
        @POST("/rest/user/logout")
        fun logout(
            @Field("phone") phone: String,
            @Field("type") type: Int
        ): Observable<DirectNone>

        @GET("/rest/profile")
        fun profile(): Observable<ProfileDirect>
//        ok line

        @FormUrlEncoded
        @PUT("/rest/profile")
        fun editProfile(@Body body: RequestBody): Observable<DirectNone>

        @FormUrlEncoded
        @POST("/rest/user/updatePwd")
        fun updatePwd(oldPassword: String, newPassword: String): Observable<DirectNone>

        @FormUrlEncoded
        @POST("/rest/user/forgetPwd")
        fun forgetPwd(code: String, newPassword: String, phonenumber: String): Observable<DirectNone>
    }

    /**
     * 菜品
     */
    interface Product {
        @GET("/user/product/list")
        fun list(@Query("restId") restId: String): Observable<ProductsDirect>

        @GET("/user/room/list")
        fun roomList(
            @Query("restId") restId: String,
            @Query("type") type: Int
        ): Observable<ListRoom>
    }

    /**
     * 点餐
     */
    interface Teamwork {
        @POST("/user/teamwork/add")
        fun add(@Body body: RequestBody): Observable<DirectNone>

        @GET("/user/teamwork/list")
        fun list(@Query("deskId") deskId: String): Observable<FoodList>

        @POST("/user/teamwork/list")
        fun remove(@Body body: RequestBody): Observable<DirectNone>
    }

    /**
     * 收货地址 测试ok
     */
    interface Address {
        @POST("/user/shipping")
        fun addAddress(@Body body: RequestBody): Observable<DirectNone>

        @PUT("/user/shipping")
        fun editAddress(@Body body: RequestBody): Observable<DirectNone>

        @GET("/user/shipping/{id}")
        fun getAddressByUid(@Path("id") id: String): Observable<AddressDirect>

        @DELETE("/user/shipping/{id}")
        fun deleteAddressByUid(@Path("id") id: String): Observable<DirectNone>

        @GET("/user/shipping/list")
        fun list(): Observable<ListAddressDirect>
    }

    interface ShouYe {
        @GET("/user/homePage/getNewProduct")
        fun newProduct(): Observable<ListFood>

        @GET("/user/homePage/getHotSale")
        fun getHotSale(
            @Query("lat") lat: String,
            @Query("lng") lng: String
        ): Observable<ListRestDirect>
    }

    interface Order {
        @POST("/user/order/cancel/{orderId}")
        suspend fun cancelOrder(@Path("orderId") orderId: String): Response<DirectNone>

        @POST("/user/order/create")
        suspend fun createOrder(@Body body: RequestBody): Response<CreatOrder>

        @GET("/user/order/detail/{id}")
        suspend fun detailOfOrder(@Path("id") id: String): Response<DirectNone>

        @GET("/user/order/list")
        suspend fun listOrder(): Response<ListOrderDirect>
    }

    interface FriendCircle {
        @GET("/user/friendCircle/browse")
        suspend fun listFriendCircle(): Response<Direct<List<FriendCircleItem>>>

        @GET("/user/friendCircle/detail")
        suspend fun detailFriendCircle(@Query("circleId") circleId: String): Response<Direct<FriendCircleDetail>>

        @POST("/user/friendCircle/comment")
        suspend fun comment(@Body body: RequestBody): Response<DirectNone>

        @DELETE("/user/friendCircle/comment")
        suspend fun deleteComment(@Query("commentId") commentId: String): Response<DirectNone>

        @POST("/user/friendCircle/send")
        suspend fun send(@Body body: RequestBody): Response<DirectNone>

        @DELETE("/user/friendCircle/delete")
        suspend fun deleteCircle(@Query("circleId ") circleId: String): Response<DirectNone>

        @POST("/user/friendCircle/myList")
        suspend fun myList(): Response<Direct<Resp.MyCircle>>

        /**
         * 点赞美食圈/取消点赞
         */
        @GET("/user/friendCircle/thumb")
        suspend fun thumb(@Query("circleId ") circleId: String): Response<DirectNone>
    }

    /**
     * 餐厅列表 测试ok
     */
    @POST("/user/rest/info")
    fun listCateen(@Body body: RequestBody): Observable<ListRestDirect>

    /**
     * 餐厅列表 测试ok
     */
    @POST("/user/rest/search")
    fun listSearch(@Body body: RequestBody): Observable<ListRestDirect>

    /**
     * 上传文件
     */
    @Multipart
    @POST("/oss/upload")
    suspend fun upload(
        @Part file: MultipartBody.Part
    ): Response<Direct<String>>

    /**
     * 创建支付
     */
    @POST("/pay/create")
    suspend fun createWeChatPay(
        @Query("amount") amount: Double,
        @Query("orderId") orderId: String,
        @Query("payType") payType: String
    ): Response<Direct<Resp.WeChatPayResp>>

    /**
     * 创建支付
     */
    @POST("/pay/create")
    suspend fun createAliPay(
        @Query("amount") amount: Double,
        @Query("orderId") orderId: String,
        @Query("payType") payType: String
    ): Response<Direct<String>>

    /**
     * 退款
     */
    @POST("/pay/refund")
    suspend fun refund(
        @Query("amount") amount: Double,
        @Query("orderAmount") orderAmount: Double,
        @Query("orderId") orderId: String,
        @Query("payType") payType: String
    ): Response<Direct<String>>
}